import { Component, OnInit, Input } from '@angular/core';

import { Platform, ModalController } from '@ionic/angular';
import { AlertController } from "@ionic/angular";

import { Base64ToGallery } from '@ionic-native/base64-to-gallery/ngx';

import { AppGlobalService } from 'src/app/shared/service/app-global.service';


import { ExportAsService, ExportAsConfig } from 'ngx-export-as';

import { EventService } from "../../shared/service/event.service";
import { IndexedDBService } from '../../shared/service/indexed-db.service';
import { QQSDK, QQShareOptions } from '@ionic-native/qqsdk/ngx';
import { HttpService } from "src/app/shared/service/http.service";
import { ShareService } from "src/app/shared/service/share.service";
declare let cordova;
declare var showLoading;
declare let EnterpriseWechat: any;
declare let Dingtalk: any;
declare let Wechat: any;
declare let $: any;
@Component({
  selector: 'app-share-page',
  templateUrl: './share-page.component.html',
  styleUrls: ['./share-page.component.scss'],
})
export class SharePageComponent implements OnInit {
  exportAsConfig: ExportAsConfig = {
    type: 'png', // the type you want to
    options: {
      useCORS: true,
    },
    elementId: 'html2canvas' // the id of html/table element
  };
  @Input() tagData: any;
  @Input() title?: any;
  customer = []; // 联系人列表
  appTypeCustom: any;
  giveMeRecommandList = [];
  secondLevelModalData: any;
  giveMeRecommendListId = 'giveMeRecommendListId_';
  isShowPublishList = false;
  publishListId = 'publishListId_';
  publishListData: any;
  recommendListTitle = '选择您需要发布的信息类型';
  shareBoxCssStyle = 'X';
  client = 'browser';
  qrCodeData = { tagData: { data: { info: { shareTopBoxCssStyle: '' } } } }; // 2023-10-19 新增分享二维码图标
  isShowButton = false; // 2023-10-17 是否在特定环境显示分享按钮
  hasQrCode = false;
  showDismissBtn = false; // 2024.07.05 新增支持展示取消按钮
  showBackButton = false; // 2024.07.09 新增参数联调
  backBtnLabel: any; // 2024.07.09 新增参数联调
  backBtnLabelCssStyle: any; // 2024.07.09 新增参数联调
  headTitle: any; // 2024.07.09 新增参数联调
  headTitleCssStyle: any; // 2024.07.09 新增参数联调
  constructor(
    private exportAsService: ExportAsService,
    public appGlobalService: AppGlobalService,
    private platform: Platform,
    private modalController: ModalController,
    private indexedDBService: IndexedDBService,
    public eventService: EventService,
    private alert: AlertController,
    private base64ToGallery: Base64ToGallery,
    private httpService: HttpService,
    private shareService: ShareService,
    private qq: QQSDK
  ) { }

  ngOnInit() {
    // 2023.12.28 是否在特定环境显示微信登录按钮   线上项目预览,测试环境项目预览,apk 则显示按钮 其他情况如H5,不显示
    this.isShowButton = this.appGlobalService.checkIsPreviewAndIsApp();
    this.recommendListTitle = this.title;

    // 2024.07.02 处理以前的数据
    if (this.tagData.data && this.tagData.data.data) {
      if (this.tagData.data.data.length > 0) {
        const array = this.tagData.data.data;
        this.tagData.data.data = null;
        this.tagData = array;
        if (this.tagData[0].showBackButton !== undefined
          && this.tagData[0].showBackButton === 'true') {
          this.showBackButton = true;
        }
        this.isShowButton = true;

        if (this.tagData[0].backBtnLabel !== undefined) {
          this.backBtnLabel = this.tagData[0].backBtnLabel;
        }
        if (this.tagData[0].backBtnLabelCssStyle !== undefined) {
          this.backBtnLabelCssStyle = this.tagData[0].backBtnLabelCssStyle;
        }
        if (this.tagData[0].headTitle !== undefined) {
          this.headTitle = this.tagData[0].headTitle;
        }
        if (this.tagData[0].headTitleCssStyle !== undefined) {
          this.headTitleCssStyle = this.tagData[0].headTitleCssStyle;
        }


      }
    }
    if (this.title === undefined) {
      if (this.tagData.data
        && typeof (this.tagData.data.length) !== 'undefined'
        && this.tagData.data[0].title1 !== undefined) {
        this.recommendListTitle = this.tagData.data[0].title1;
      }
    }

    if (this.tagData && this.tagData[0] && this.tagData[0].shareBoxCssStyle !== undefined) {
      this.shareBoxCssStyle = this.tagData[0].shareBoxCssStyle;
    } else if (this.tagData
      && this.tagData.data
      && this.tagData.data[0]
      && this.tagData.data[0].shareBoxCssStyle !== undefined) {
      this.shareBoxCssStyle = this.tagData.data[0].shareBoxCssStyle;
    }
    this.giveMeRecommendListId += new Date().getTime();
    this.publishListId += new Date().getTime();
    const bodyStyles = window.getComputedStyle(document.body);
    this.appTypeCustom = bodyStyles.getPropertyValue('--appTypeCustom').trim().replace('"', '').replace('"', '');
    this.client = localStorage.getItem('platform');

    this.checkShowDismissBtn();



    if (this.appTypeCustom === 'LJ') {
      try {
        if ((this.tagData.type && this.tagData.type === 'array') || Array.isArray(this.tagData)) {
          let dataArray = [];
          if (this.tagData.data && this.tagData.data.length > 0) {
            dataArray = this.tagData.data;
          } else if (this.tagData && Array.isArray(this.tagData)) {
            dataArray = this.tagData;
          }

          // tslint:disable-next-line:prefer-for-of
          for (let index = 0; index < dataArray.length; index++) {
            const element = dataArray[index];
            if (element.name !== undefined && element.name === 'qrCodeData') {
              this.qrCodeData.tagData.data.info = element;
              this.hasQrCode = true;
            } else {
              this.giveMeRecommandList.push(element);
            }
          }
        } else {
          if (this.tagData.zhufang) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.zhufang.link, label: this.tagData.zhufang.label, content: this.tagData.zhufang.content, icon: this.tagData.zhufang.icon });
          }
          if (this.tagData.shangpu) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.shangpu.link, label: this.tagData.shangpu.label, content: this.tagData.shangpu.content, icon: this.tagData.shangpu.icon });
          }
          if (this.tagData.xizilou) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.xizilou.link, label: this.tagData.xizilou.label, content: this.tagData.xizilou.content, icon: this.tagData.xizilou.icon });
          }
          if (this.tagData.changfangck) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.changfangck.link, label: this.tagData.changfangck.label, content: this.tagData.changfangck.content, icon: this.tagData.changfangck.icon });
          }
          if (this.tagData.wyzufang) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.wyzufang.link, label: this.tagData.wyzufang.label, content: this.tagData.wyzufang.content, icon: this.tagData.wyzufang.icon });
          }
          if (this.tagData.wymaifang) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.wymaifang.link, label: this.tagData.wymaifang.label, content: this.tagData.wymaifang.content, icon: this.tagData.wymaifang.icon });
          }
          if (this.tagData.xfchushou) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ link: this.tagData.xfchushou.link, label: this.tagData.xfchushou.label, content: this.tagData.xfchushou.content, icon: this.tagData.xfchushou.icon });
          }
          // 短信
          if (this.tagData.sms) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'sms', link: this.tagData.sms.link, label: this.tagData.sms.label, content: this.tagData.sms.content, icon: this.tagData.sms.icon });
          }
          // 快手
          if (this.tagData.kwai) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'kwai', link: this.tagData.kwai.link, label: this.tagData.kwai.label, content: this.tagData.kwai.content, icon: this.tagData.kwai.icon });
          }
          // QQ
          if (this.tagData.qq) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'qq', link: this.tagData.qq.link, label: this.tagData.qq.label, content: this.tagData.qq.content, icon: this.tagData.qq.icon });
          }
          // QQ空间
          if (this.tagData.qzone) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'qzone', link: this.tagData.qzone.link, label: this.tagData.qzone.label, content: this.tagData.qzone.content, icon: this.tagData.qzone.icon });
          }
          // wechat
          if (this.tagData.wechat) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'wechat', link: this.tagData.wechat.link, label: this.tagData.wechat.label, content: this.tagData.wechat.content, icon: this.tagData.wechat.icon });
          }
          // moment
          if (this.tagData.moment) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'moment', link: this.tagData.moment.link, label: this.tagData.moment.label, content: this.tagData.moment.content, icon: this.tagData.moment.icon });
          }
          // 58
          if (this.tagData.city) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'city', link: this.tagData.city.link, label: this.tagData.city.label, content: this.tagData.city.content, icon: this.tagData.city.icon });
          }
          // 抖音
          if (this.tagData.tikTok) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'tikTok', link: this.tagData.tikTok.link, label: this.tagData.tikTok.label, content: this.tagData.tikTok.content, icon: this.tagData.tikTok.icon });
          }
          // 复制链接
          if (this.tagData.copy) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'copy', link: this.tagData.copy.link, label: this.tagData.copy.label, content: this.tagData.copy.content, icon: this.tagData.copy.icon });
          }
          // 画报
          if (this.tagData.posterSharing) {
            // tslint:disable-next-line:max-line-length
            this.giveMeRecommandList.push({ name: 'posterSharing', link: this.tagData.posterSharing.link, label: this.tagData.posterSharing.label, content: this.tagData.posterSharing.content, icon: this.tagData.posterSharing.icon });
          }
        }
      } catch (error) {
      }
    }
    // this.indexedDBService.getLastContactCustomerList(res => {
    //   this.customer = res;
    // });
  }


  // 检查是否显示取消按钮
  checkShowDismissBtn() {
    let array;
    if (Array.isArray(this.tagData)) {
      array = this.tagData;
    } else if (this.tagData
      && this.tagData.data
      && Array.isArray(this.tagData.data)) {
      array = this.tagData.data;
    } else if (this.tagData.data
      && this.tagData.data.data
      && Array.isArray(this.tagData.data.data)) {
      array = this.tagData.data;
    }
    if (array && array.length > 0) {
      if (array[0] && array[0].showDismissBtn !== undefined && array[0].showDismissBtn === 'true') {
        this.showDismissBtn = true;
      }
    }

  }


  dismiss() {
    this.modalController.dismiss({
      dismissed: true
    });
  }
  go(obj) {
    this.dismiss();
    const pageParams = {
      pageId: obj.target,
      params: obj.params,
      sessionId: localStorage.getItem('sessionId')
    };
    this.appGlobalService.goToForward(pageParams);
  }
  async shareDetail(nickname, shareToUserId?) {
    const alert = await this.alert.create({
      message: "确定发送详情给" + nickname + "吗？",
      buttons: [
        {
          text: "取消",
          role: "cancel",
          cssClass: "secondary",
          handler: () => { }
        },
        {
          text: "确定",
          handler: () => {
            // 发送商机消息 add by andrew.wen
            if (localStorage.getItem('shareOppDetail')) {
              const oppDetail = JSON.parse(localStorage.getItem('shareOppDetail'));
              // localStorage.removeItem('shareOppDetail');
              localStorage.setItem('onSendWebSocketMessageTag', 'true');
              const shareFromUserId = localStorage.getItem("connUserId");
              const nowDate = Date.now();
              const message = {
                text: oppDetail.title,
                toId: shareToUserId,
                fromId: shareFromUserId,
                key: shareToUserId + '-' + shareFromUserId,
                type: 'opp',
                rentunit: oppDetail.rentunit ? oppDetail.rentunit : '元/月',
                opportunity_id: oppDetail.opportunity_id,
                title: oppDetail.title,
                imags: oppDetail.imags ? oppDetail.imags : '../../../assets/img/375x250@2x.png',
                pluginId: oppDetail.pluginId,
                big_district: oppDetail.big_district ? oppDetail.big_district : '',
                district: oppDetail.district ? oppDetail.district : '',
                area: oppDetail.area ? oppDetail.area : '',
                industry: oppDetail.industry ? oppDetail.industry : '',
                rent: oppDetail.rent ? oppDetail.rent : '',
                transfer_fee: oppDetail.transfer_fee ? oppDetail.transfer_fee : '',
                nowDate
              };
              this.eventService.eventEmit.emit("onSendWebSocketMessage", message);
              this.appGlobalService.showToast('发送成功', 2000, 'middle');
            }
          }
        }
      ]
    });
    await alert.present();

  }

  //  复制链接
  copyUrl(str) {
    this.dismiss();
    this.appGlobalService.copyString(str);
  }

  savePic() {
    const that = this;
    const element = document.getElementById('html2canvas');
    const targetElement = document.getElementById('transfer-bg').cloneNode(true);
    // crossOrigin="anonymous"
    element.appendChild(targetElement);

    setTimeout(() => {
      const dom = element.querySelector('#transfer-bg').querySelectorAll('img');
      // tslint:disable-next-line:prefer-for-of
      for (let i = 0; i < dom.length; i++) {
        dom[i].crossOrigin = 'anonymous';
      }
      this.exportAsService.get(this.exportAsConfig).subscribe(content => {
        that.download(content);
        element.removeChild(targetElement);
        that.modalController.dismiss();
      });
    }, 500);

  }
  posterSharing(item) {
    this.modalController.dismiss();
    const tmpSessionId = localStorage.getItem('sessionId');
    const pageParams = {
      pageId: item.link.target,
      params: item.link.params ? item.link.params : {},
      sessionId: tmpSessionId
    };
    this.appGlobalService.goToForward(pageParams);
  }
  download(dataUrl) {
    if (localStorage.getItem('client') === 'BROWSER') {
      const myBlob = this.dataURLtoBlob(dataUrl);
      const myUrl = URL.createObjectURL(myBlob);
      this.downloadFile(myUrl, 'deatil');
    } else {
      this.base64ToGallery.base64ToGallery(dataUrl, { prefix: '_img', mediaScanner: true }).then(
        (res) => {
          console.log('Saved image to gallery ', res);
          this.appGlobalService.showToast('保存成功!', 1500, 'top');
        },
        err => console.log('Error saving image to gallery ', err)
      );
    }

  }
  dataURLtoBlob(dataurl) {
    const arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
      bstr = atob(arr[1]);
    let n = bstr.length;
    const u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
  }

  downloadFile(url, name) {
    const a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("download", name);
    a.setAttribute("target", "_blank");
    const clickEvent = document.createEvent("MouseEvents");
    clickEvent.initEvent("click", true, true);
    a.dispatchEvent(clickEvent);
  }
  // transfer-bg
  // 获取url参数
  getUrlParam(name) {
    // 取得url中?后面的字符
    const query = window.location.search.substring(1);
    // 把参数按&拆分成数组
    const paramArr = query.split("&");
    // tslint:disable-next-line: prefer-for-of
    for (let i = 0; i < paramArr.length; i++) {
      const pair = paramArr[i].split("=");
      if (pair[0] === name) {
        return pair[1];
      }
    }
    return (false);
  }

  shareSMS(title?, content?, imageUrl?, webpageUrl?) {
    try {

      this.copyUrl(content);
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }

  }

  shareKS(title?, content?, imageUrl?, webpageUrl?) {
    try {
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }
  shareEnterpriseWechat(title?, content?, imageUrl?, webpageUrl?, type?) {
    try {
      this.dismiss();
      EnterpriseWechat.share({
        message: {
          title,
          description: content,
          thumb: imageUrl,
          webpageUrl
        }, type
      }, () => {
        console.log('success');
      }, (reason) => {
        console.log('error----->' + JSON.stringify(reason));
      });
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }
  shareWeiXin(title?, content?, imageUrl?, webpageUrl?) {
    try {
      Wechat.share({
        message: {
          title,
          description: content,
          thumb: imageUrl,
          media: {
            type: Wechat.Type.WEBPAGE,
            webpageUrl
          }
        }, scene: Wechat.Scene.SESSION
      }, () => {
        console.log('success');
      }, (reason) => {
        console.log('error----->' + JSON.stringify(reason));
      });
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }

  }

  shareMoments(title?, content?, imageUrl?, webpageUrl?) {
    try {
      Wechat.share({
        message: {
          title,
          description: content,
          thumb: imageUrl,
          media: {
            type: Wechat.Type.WEBPAGE,
            webpageUrl
          }
        }, scene: Wechat.Scene.TIMELINE     //TIMELINE朋友圈  SESSION会话   FAVORITE 收藏 默认朋友圈
      }, () => {
        console.log('success');
      }, (reason) => {
        console.log('error----->' + JSON.stringify(reason));
      });
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }

  }

  shareQQ(title?, content?, imageUrl?, webpageUrl?) {
    try {
      const shareNewsOptions: QQShareOptions = {
        client: this.qq.ClientType.QQ,
        title,
        scene: this.qq.Scene.QQ,
        url: webpageUrl,
        image: imageUrl,
        description: content
      };
      this.qq.shareNews(shareNewsOptions)
        .then(() => {
          console.log('shareText success');
        })
        .catch(error => {
          console.log(error);
        });
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }

  shareQQZone(title?, content?, imageUrl?, webpageUrl?) {
    try {
      const shareNewsOptions: QQShareOptions = {
        client: this.qq.ClientType.QQ,
        title,
        scene: this.qq.Scene.QQZone,
        url: webpageUrl,
        image: imageUrl,
        description: content
      };
      this.qq.shareImage(shareNewsOptions)
        .then(() => {
          console.log('shareText success');
        })
        .catch(error => {
          console.log(error);
        });
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }

  shareDingTalk(title?, content?, imageUrl?, webpageUrl?) {
    try {
      const msgObj = {
        title,
        pageURL: webpageUrl,
        thumbURL: imageUrl,
        messageDescription: content
      };
      Dingtalk.shareWebObject(() => {
        console.log('shareText success');
      }, error => {
        console.log(error);
      }, msgObj);
      this.dismiss();
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }

  iconButtonClick(obj) {
    try {
      if (obj) {
        if (obj.tips) {
          this.appGlobalService.showToast(obj.tips, 2000, "middle");
          return;
        }
        if (obj.link && obj.link.type === 'page' && (!obj.link.params || !obj.link.params.secondLevelModal)) {
          const targetObj = { pageId: obj.link.target, params: obj.link.params, sessionId: localStorage.getItem('sessionId') };
          this.appGlobalService.goToForward(targetObj);
          this.dismiss();
        } else if (obj.link && obj.link.type === 'page' && obj.link.params.secondLevelModal) {
          const params = {
            sessionId: localStorage.getItem("sessionId"),
            pageId: obj.link.target,
            params: obj.link.params
          };
          this.httpService.post('application/page', params, res => {
            this.isShowPublishList = true;
            this.secondLevelModalData = JSON.parse(res.script).views[0].tags[0].data;
            $('#' + this.giveMeRecommendListId).fadeOut(0);
            $('#p_' + this.giveMeRecommendListId).fadeOut(0);
            $('#' + this.publishListId).fadeIn(200);
            $('#p_' + this.publishListId).fadeIn(200);
          });
        } else {
          this.publishClick(obj);
        }
      }
    } catch (error) {
      this.dismiss();
    }
  }

  async publishClick(obj) {
    if (obj.link && obj.link.type === 'page' && obj.name !== 'checkSubmit') {
      const targetObj = { pageId: obj.link.target, params: obj.link.params, sessionId: localStorage.getItem('sessionId') };
      this.appGlobalService.goToForward(targetObj);
      this.dismiss();
    } else {
      if (obj && obj.name) {
        switch (obj.name) {
          case 'qq':
            if (obj.isShareQrImg) {
              localStorage.setItem('qrCodeRequestCode', '1');
              // tslint:disable-next-line:max-line-length
              this.eventService.eventEmit.emit("qrCode", { title: obj.title, content: obj.content, imageUrl: obj.imageUrl, webpageUrl: obj.webpageUrl, name: obj.name });
            } else {
              this.shareService.shareQQ(obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.submit);
            }
            break;
          case 'qzone':
            this.shareService.shareQQZone(obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.submit);
            break;
          case 'wechat':
            if (obj.isShareQrImg) {
              localStorage.setItem('qrCodeRequestCode', '1');
              // tslint:disable-next-line:max-line-length
              this.eventService.eventEmit.emit("qrCode", { title: obj.title, content: obj.content, imageUrl: obj.imageUrl, webpageUrl: obj.webpageUrl, name: obj.name });
            } else if (obj.isMiniApp !== undefined) {
              // 需要检查状态是否已经上传图片成功
              if (obj.isUpload === '1') {
                showLoading();
                let a = 1;
                while (a === 1) {
                  if (this.appGlobalService.isUploadImgComplete) {
                    this.shareService.shareWeiXinMiniApp
                      (obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.wechatMiniProgrameId, obj.submit);
                    a = 0;
                    this.httpService.hideLoading();
                    break;
                  }
                  await this.sleep(10);
                }
                // 防止死循环
                setTimeout(() => {
                  a = 0;
                  this.httpService.hideLoading();
                }, 5000);

              } else if (obj.isUpload === '0') {
                this.shareService.shareWeiXinMiniApp
                  (obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.wechatMiniProgrameId, obj.submit);
              }
            } else {
              this.shareService.shareWeiXin(obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.submit);
            }
            break;
          case 'moment':
            if (obj.isShareQrImg) {
              localStorage.setItem('qrCodeRequestCode', '1');
              // tslint:disable-next-line:max-line-length
              this.eventService.eventEmit.emit("qrCode", { title: obj.title, content: obj.content, imageUrl: obj.imageUrl, webpageUrl: obj.webpageUrl, name: obj.name });
            } else {
              this.shareService.shareMoments(obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.submit);
            }
            break;
          case '58':
            this.shareService.share58(obj);
            break;
          case 'tikTok': // 抖音
            if (obj.isInValidImgPosterSharing) {
              this.shareService.shareDouyinForInValidImg(obj.link.fieldLinkType);
            } else if (obj.isShareQrImg) {
              localStorage.setItem('qrCodeRequestCode', '1');
              // tslint:disable-next-line:max-line-length
              this.eventService.eventEmit.emit("qrCode", { title: obj.title, content: obj.content, imageUrl: obj.imageUrl, webpageUrl: obj.webpageUrl, name: obj.name });
            } else {
              this.shareService.shareDouyin(obj.title, obj.content, obj.imageUrls, obj.webpageUrl,
                (obj.ifVideo === "true" || obj.ifVideo === true) ? 1 : 0, obj.submit);
            }
            break;
          case 'kwai': // 快手 https://play.google.com/store/apps/details?id=com.kwai.video&hl=zh&gl=US
            this.shareService.shareKuaishou(obj.title, obj.content, obj.imageUrl, obj.webpageUrl, obj.shareType, obj.submit);
            break;
          case 'copy':
            this.copyUrl(obj.webpageUrl);
            break;
          case 'sms':
            this.copyUrl(obj.webpageUrl);
            break;
          case 'savePic':
            // this.shareService.savePic();
            localStorage.setItem('qrCodeRequestCode', '1');
            this.eventService.eventEmit.emit("qrCode", 1);
            break;
          case 'posterSharing':
            this.posterSharing(obj.link.fieldLinkType);
            break;
          // 蜂喔商户1.6.23 新增企业微信分享
          case 'enterpriseWechat':
            this.shareService.shareEnterpriseWechat(obj.title, obj.content, obj.imageUrl, obj.webpageUrl,
              obj.shareType, obj.submit);
            break;

          case 'checkSubmit':
            this.shareService.checkSubmit(obj.link, obj.submit);
            break;

          default:

            console.log('...gotoSharePage');
            break;
        }


        this.dismiss();


        // 2023年11月3日新增
        if (obj.isRefreshAfterClickBackDrop !== undefined) {
          setTimeout(() => {
            this.appGlobalService.reloadCurrentPage(0);
          }, 600);
        }
      }
    }
  }

  sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

  goBackToGiveMeRecommend() {
    $('#' + this.publishListId).fadeOut(0);
    $('#p_' + this.publishListId).fadeOut(0);
    $('#' + this.giveMeRecommendListId).fadeIn(200);
    $('#p_' + this.giveMeRecommendListId).fadeIn(200);
    this.isShowPublishList = false;
  }

}
